#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "module.h"
#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <sys/select.h>
#include "keymgt.h"
#include <sys/err.h>
#include "apitrans.h"

extern sys_apitrans_t sysapi;

int modem_get_sq(void)
{
	int (*pmodem_get_sq)(void);    
    pmodem_get_sq = sysapi(MODEM_GET_SQ_API);
    if (pmodem_get_sq) {
        return pmodem_get_sq();
    }
    return -API_UNSUPPORTED_ERR;
}


int modem_get_info(modem_info_em type, char *info)
{
	int (*pmodem_get_info)(modem_info_em type, char *info);
    pmodem_get_info = sysapi(MODEM_GET_INFO_API);
    if (pmodem_get_info) {
        return pmodem_get_info(type, info);
    }
    return -API_UNSUPPORTED_ERR;
	
	}
int modem_get_station_info(modem_station_info_t * info)
{
    int (*pmodem_get_station_info)(modem_station_info_t * info);
    pmodem_get_station_info = sysapi(MODEM_GET_STATION_INFO_API);
    if (pmodem_get_station_info) {
        return pmodem_get_station_info(info);
    }
    return -API_UNSUPPORTED_ERR;
}

/*TCP API*/
int tcp_open(tcp_dev_em type)
{
    int (*ptcp_open)(tcp_dev_em type);
    ptcp_open = sysapi(TCP_OPEN_API);
    if (ptcp_open) {
        return ptcp_open(type);
    }
    return -API_UNSUPPORTED_ERR;	
}
int tcp_close(int fd)
{
	int (*ptcp_close)(int fd);
    ptcp_close = sysapi(TCP_CLOSE_API);
    if (ptcp_close) {
        return ptcp_close(fd);
    }
    return -API_UNSUPPORTED_ERR;	
	
}
int tcp_connect(int fd, const char *ip, int port, int timeout)
{
	int (*ptcp_connect)(int fd, const char *ip, int port, int timeout);
    ptcp_connect = sysapi(TCP_CONNECT_API);
    if (ptcp_connect) {
        return ptcp_connect(fd, ip, port, timeout);
    }
    return -API_UNSUPPORTED_ERR;	
}	 
int tcp_write(int fd, const char* data, int data_len, int timeout)
{
    int (*ptcp_write)(int fd, const char* data, int data_len, int timeout);
    ptcp_write = sysapi(TCP_WRITE_API);
    if (ptcp_write ){
        return ptcp_write(fd, data, data_len, timeout);
    }
    return -API_UNSUPPORTED_ERR;
}
int tcp_read(int fd, char* buf, int req_len, int timeout)
{
    int (*ptcp_read)(int fd, char* buf, int req_len, int timeout);
    ptcp_read = sysapi(TCP_READ_API);
    if (ptcp_read ){
        return ptcp_read(fd, buf, req_len, timeout);
    }
    return -API_UNSUPPORTED_ERR;
}

